//
//  CPPPerson.cpp
//  test_cpp_lib
//
//  Created by CallMeDoby on 2021/1/3.
//

#include "CPPPerson.hpp"
#include "CBridging.h"

CPPPerson::CPPPerson() {
    this->name = "管理员";
    this->age = 999;
    this->isMale = true;
}

CPPPerson::CPPPerson(const char* name, int age, bool isMale) {
    this->name = name;
    this->age = age;
    this->isMale = isMale;
}

void CPPPerson::printInfo() {
    cout << "name = " << this->name <<" age = " << this->age << " is Male = " << this->isMale << endl;
}

const char* CPPPerson::getName() {
    return this->name.data();
}

void CPPPerson::callSwiftFunc(int value) {
    cpp_swiftFuncIMP(value);
}

CPPPerson::~CPPPerson() {
    cout << "释放" << endl;
}

CPPPersonModel PMCreate() {
    return new CPPPerson();
}

CPPPersonModel PMCreateBy(const char * name, int age, int isMail) {
    return new CPPPerson(name, age, isMail != 0);
}

void PMPrintInfo(CPPPersonModel model) {
    CPPPerson *p = (CPPPerson*)model;
    p->printInfo();
}

const char * PMGetName(CPPPersonModel model) {
    CPPPerson *p = (CPPPerson*)model;
    return p->getName();
}

void PMDestoryModel(CPPPersonModel model) {
    CPPPerson *p = (CPPPerson*)model;
    delete p;
}

void PMCallSwift(CPPPersonModel model, int value) {
    CPPPerson *p = (CPPPerson*)model;
    p->callSwiftFunc(value);
}
